grammar VecMath;

@members {
    print(s:string | undefined){ 
        if(s){
            process.stdout.write(s)
        }
    }
}

prog : stat+;

stat : ID {this.print($ID.text)} '='{this.print('=')} expr  {this.print('\n')}
    | 'print '{this.print('print ')} expr {this.print('\n')}
    ;
expr : multExpr ('+'{this.print('+')} multExpr)*;

multExpr : primary (('*'{this.print('*')}|'.'{this.print('.')}) primary)*;

primary : INT {this.print($INT.text)}
    | ID {this.print($ID.text)}
    | '[' {this.print('[');} expr (','{this.print(", ")} expr)* ']' {this.print("]")}
    ;

ID : [a-z]+;
INT : [0-9]+;
WS : (' '|'\r'|'\n') -> skip;